package day01.com.web.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.websocket.Session;

import day01.com.service.ImgService;
import day01.com.service.impl.ImgServiceImpl;

/**
 * Servlet implementation class Ioginservlet
 */
@WebServlet("/Ioginservlet")
public class Ioginservlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Ioginservlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		String userName = request.getParameter("username");
		String userPass = request.getParameter("userpass");
		ImgService imgImpl = new ImgServiceImpl();
		int num = imgImpl.UserLogin(userName,userPass);
		HttpSession session = request.getSession();
		if(num==-1) {
			session.setAttribute("word", "登录失败，用户名错误");
			response.sendRedirect("ok.jsp");
		}else if(num==-2) {
			session.setAttribute("word", "登录失败，密码错误");
			response.sendRedirect("ok.jsp");
		}else if(num==1) {
			session.setAttribute("word", "登录成功");
			response.sendRedirect("ok.jsp");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
